package com.efast.cafe.portal.controller.doc;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.efast.cafe.framework.bean.ResultBean;
import com.efast.cafe.framework.controller.AbstractController;
import com.efast.cafe.framework.exception.ServiceException;
import com.efast.cafe.portal.bean.doc.DocAttrsQueryBean;
import com.efast.cafe.portal.entity.doc.DocAttrs;
import com.efast.cafe.portal.service.doc.IDocAttrsService;

@Controller
@RequestMapping("/doc")
public class DocAttrsController  extends  AbstractController{
	
	@Autowired
	private IDocAttrsService docAttrsService;

	@RequestMapping(value="/attrs/list")
	public @ResponseBody ResultBean queryAttrList(@ModelAttribute DocAttrsQueryBean docAttrsQueryBean){
		ResultBean result = new ResultBean(true,null);
		try {
			result.setObject(docAttrsService.queryDocAttrs(docAttrsQueryBean));
		} catch (Exception e) {
			e.printStackTrace();
			result.setSuccess(false);
			if (e instanceof ServiceException) {
				result.setErrorCode(e.getMessage());
			} else {
				result.setErrorCode(ResultBean.ERROR_CODE_SYSTEM);
			}
		}
		
		return result;
	}
	@RequestMapping(value="/attrs/add")
	public @ResponseBody ResultBean saveDocAttrs(@ModelAttribute DocAttrs docAttrs){
		ResultBean result =new ResultBean(true, null);
		try {
			docAttrsService.addDocAttrs(docAttrs);
		} catch (Exception e) {
			e.printStackTrace();
			result.setSuccess(false);
			if (e instanceof ServiceException) {
				result.setErrorCode(e.getMessage());
			} else {
				result.setErrorCode(ResultBean.ERROR_CODE_SYSTEM);
			}
		}
		return result;
	}
	
	@RequestMapping(value="/attrs/update")
	public @ResponseBody ResultBean updateDocAttrs(@ModelAttribute DocAttrs docAttrs){
		ResultBean result =new ResultBean(true, null);
		try {
			docAttrsService.updateDocAttrs(docAttrs);
		} catch (Exception e) {
			e.printStackTrace();
			result.setSuccess(false);
			if (e instanceof ServiceException) {
				result.setErrorCode(e.getMessage());
			} else {
				result.setErrorCode(ResultBean.ERROR_CODE_SYSTEM);
			}
		}
		return result;
	}
	
	@RequestMapping(value="/attrs/delete")
	public @ResponseBody ResultBean deleteDocAttrs(@RequestParam Integer id){
		ResultBean result =new ResultBean(true, null);
		try {
			docAttrsService.deleteDocAttrs(id);
		} catch (Exception e) {
			e.printStackTrace();
			result.setSuccess(false);
			if (e instanceof ServiceException) {
				result.setErrorCode(e.getMessage());
			} else {
				result.setErrorCode(ResultBean.ERROR_CODE_SYSTEM);
			}
		}
		return result;
	}
}
